﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BattleShip_MongoDB
{
    public class Player
    {
        private const int iShipCount = 5;
        private List<Ship> PlayerShips;
        private int iAliveShip5;
        private int iAliveShip4;
        private int iAliveShip3;
        private int iAliveShip2;
        private int iNoValidShip;
        
        public Player()
        {
            PlayerShips = new List<Ship>(5);
            this.iAliveShip2 = 1;
            this.iAliveShip3 = 2;
            this.iAliveShip4 = 1;
            this.iAliveShip5 = 1;
        }

        public int GetNoAliveShip()
        {
            int iRetValue = 0;

            iRetValue = iAliveShip2 + iAliveShip3 + iAliveShip4 + iAliveShip5;

            return iRetValue;
        }

        public int GetNoValidShip()
        {
            return iNoValidShip;
        }

        public void AddShip(Ship _ShipTemp)
        {
            PlayerShips.Add(_ShipTemp);
            iNoValidShip++;

            return;
        }

        public void ShotedAt(Point point)
        {
            bool bShipStatusAfterShoted = true;

            for (int i = 0; i < iShipCount; i++)
            {
                if (PlayerShips[i].GetShipStatus())
                {
                    bShipStatusAfterShoted = PlayerShips[i].ShotedAt(point);

                    if (bShipStatusAfterShoted == false)
                    {
                        switch (PlayerShips[i].GetShipSize())
                        {
                            case 2:
                                iAliveShip2--;
                                break;
                            case 3:
                                iAliveShip3--;
                                break;
                            case 4:
                                iAliveShip4--;
                                break;
                            case 5:
                                iAliveShip5--;
                                break;
                            default:
                                break;
                        }

                        break;
                    }
                }
            }

            return;
        }
    }
}
